Re: [SQL] select in update - Mailing list pgsql-sql

From Herouth Maoz
Subject Re: [SQL] select in update
Date
Msg-id l03110700b28047415e6d@[147.233.159.109]
Whole thread Raw
In response to Re: [SQL] select in update  (Engard Ferenc <fery@pons.sote.hu>)
List pgsql-sql
At 12:05 +0200 on 24/11/98, Engard Ferenc wrote:


> Well, then a little bit complex problem:
> two tables: A (var), B (var1,var2). I would like to replace the A.var
> if it exists in B.var2 with B.var1. Is it good?
>
> UPDATE a
> SET a.var=b.var1
> FROM b                <-- or maybe I need to put 'a' here too?
> WHERE a.var=b.var2;
>
> I don't need to tell that there are rows which cannot find in B? (In
> this case it shouldn't change.)

It's a bit hard to understand what you want to be done, and what you
*don't* want to be done.

The above seems to be the right update. But you better give a short example
of what you want. In the example you gave, if the data is:

A
==
1
2
3
4

B
==
var1  var2
====  ====
10    1
30    3
50    5

Then after the update, A will be:

10
2
30
4

This is because 1 and 3 were matched, and 2 and 4 weren't matched. If that
is what you wanted, then your update statement is correct.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



pgsql-sql by date:

Previous
From: Hitesh Kumar Gulati
Date:
Subject: Re: Problem
Next
From: jwieck@debis.com (Jan Wieck)
Date:
Subject: Re: [HACKERS] Re: [SQL] cursor and update + view